package edu.task.controller;

import edu.task.common.base.BaseController;
import edu.task.common.result.RestResult;
import edu.task.model.vo.SysExplainVO;
import edu.task.model.vo.SysSubtaskVO;
import edu.task.service.SysExplainService;
import edu.task.service.SysSubtaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 个人说明表控制层
 */
@RestController
@RequestMapping("/system/subtask")
public class SysSubtaskController extends BaseController {
    @Autowired
    SysSubtaskService subtaskService;

    /**
     * 显示子任务表所有数据
     */
    @GetMapping("/list")
    public RestResult list() {
        RestResult ajax = RestResult.success();
        ajax.put(RestResult.DATA_TAG, subtaskService.selectSubtaskList());
        return ajax;
    }

    /**
     * 子任务新增
     */
    @PostMapping
    public RestResult add(@RequestBody SysSubtaskVO subtask) {
        boolean flag = subtaskService.insertSubtask(subtask);
        return toAjax(flag ? 1 : 0);
    }

    /**
     * 删除子任务
     */
    @DeleteMapping("/{subtaskId}")
    public RestResult remove(@PathVariable Long subtaskId){
        return toAjax(subtaskService.deleteSubtaskById(subtaskId));
    }

    /**
     * 修改新增
     */
    @PutMapping
    public RestResult edit(@Validated @RequestBody SysSubtaskVO subtask) {
        boolean flag = subtaskService.updateSubtask(subtask);
        return toAjax(flag ? 1 : 0);
    }

    /**
     * 根据任务ID显示子任务表所有数据
     */
    @GetMapping("/list/{taskId}")
    public RestResult index(@PathVariable(value = "taskId", required = false) Long taskId){
        RestResult ajax = RestResult.success();
        ajax.put(RestResult.DATA_TAG, subtaskService.selectSubtaskListByTaskId(taskId));
        return ajax;
    }

}
